home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / IOS.H < prev    next >
C/C++ Source or Header  |  1993-11-23  |  6KB  |  199 lines

  1. /***
  2. *ios.h - definitions/declarations for the ios class.
  3. *
  4. *   Copyright (c) 1990-1992, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *   This file defines the classes, values, macros, and functions
  8. *   used by the ios class.
  9. *   [AT&T C++]
  10. *
  11. ****/
  12.  
  13. #ifndef _INC_IOS
  14. #define _INC_IOS
  15.  
  16.  
  17. #ifdef M_I86HM
  18. #define _HFAR_ __far
  19. #else 
  20. #define _HFAR_
  21. #endif 
  22.  
  23. #ifndef NULL
  24. #define NULL    0
  25. #endif 
  26.  
  27. #ifndef EOF
  28. #define EOF (-1)
  29. #endif 
  30.  
  31. // Force word packing to avoid possible -Zp override
  32. #pragma pack(2)
  33.  
  34. #pragma warning(disable:4505)       // disable unwanted /W4 warning
  35. // #pragma warning(default:4505)    // use this to reenable, if necessary
  36.  
  37. class streambuf;
  38. class ostream;
  39.  
  40. class ios {
  41.  
  42. public:
  43.     enum io_state {  goodbit = 0x00,
  44.              eofbit  = 0x01,
  45.              failbit = 0x02,
  46.              badbit  = 0x04 };
  47.  
  48.     enum open_mode { in        = 0x01,
  49.              out       = 0x02,
  50.              ate       = 0x04,
  51.              app       = 0x08,
  52.              trunc     = 0x10,
  53.              nocreate  = 0x20,
  54.              noreplace = 0x40,
  55.              binary    = 0x80 };    // CONSIDER: not in latest spec.
  56.  
  57.     enum seek_dir { beg=0, cur=1, end=2 };
  58.  
  59.     enum {  skipws     = 0x0001,
  60.         left       = 0x0002,
  61.         right      = 0x0004,
  62.         internal   = 0x0008,
  63.         dec        = 0x0010,
  64.         oct        = 0x0020,
  65.         hex        = 0x0040,
  66.         showbase   = 0x0080,
  67.         showpoint  = 0x0100,
  68.         uppercase  = 0x0200,
  69.         showpos    = 0x0400,
  70.         scientific = 0x0800,
  71.         fixed      = 0x1000,
  72.         unitbuf    = 0x2000,
  73.         stdio      = 0x4000
  74.                  };
  75.  
  76.     static const long basefield;    // dec | oct | hex
  77.     static const long adjustfield;  // left | right | internal
  78.     static const long floatfield;   // scientific | fixed
  79.  
  80.     ios(streambuf*);            // differs from ANSI
  81.     virtual ~ios();
  82.  
  83.     inline long flags() const;
  84.     inline long flags(long _l);
  85.  
  86.     inline long setf(long _f,long _m);
  87.     inline long setf(long _l);
  88.     inline long unsetf(long _l);
  89.  
  90.     inline int width() const;
  91.     inline int width(int _i);
  92.  
  93.     inline ostream* tie(ostream* _os);
  94.     inline ostream* tie() const;
  95.  
  96.     inline char fill() const;
  97.     inline char fill(char _c);
  98.  
  99.     inline int precision(int _i);
  100.     inline int precision() const;
  101.  
  102.     inline int rdstate() const;
  103.     inline void clear(int _i = 0);
  104.  
  105. //  inline operator void*() const;
  106.     operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  107.     inline int operator!() const;
  108.  
  109.     inline int  good() const;
  110.     inline int  eof() const;
  111.     inline int  fail() const;
  112.     inline int  bad() const;
  113.  
  114.     inline streambuf* rdbuf() const;
  115.  
  116.     inline long _HFAR_ & iword(int) const;
  117.     inline void _HFAR_ * _HFAR_ & pword(int) const;
  118.  
  119.     static long bitalloc();
  120.     static int xalloc();
  121.     static void sync_with_stdio();
  122.  
  123. protected:
  124.     ios();
  125.     ios(const ios&);            // treat as private
  126.     ios& operator=(const ios&);
  127.     void init(streambuf*);
  128.  
  129.     enum { skipping, tied };
  130.     streambuf*  bp;
  131.  
  132.     int     state;
  133.     int     ispecial;           // not used
  134.     int     ospecial;           // not used
  135.     int     isfx_special;       // not used
  136.     int     osfx_special;       // not used
  137.     int     x_delbuf;           // if set, rdbuf() deleted by ~ios
  138.  
  139.     ostream* x_tie;
  140.     long    x_flags;
  141.     int     x_precision;
  142.     int     x_width;
  143.     char    x_fill;
  144.  
  145.     static void (*stdioflush)();    // not used
  146. public:
  147.     int delbuf() const { return x_delbuf; }
  148.     void    delbuf(int _i) { x_delbuf = _i; }
  149.  
  150. private:
  151.     static long x_maxbit;
  152.     static long _HFAR_ * x_statebuf;  // used by xalloc()
  153.     static int x_curindex;
  154. // consider: make interal static to ios::sync_with_stdio()
  155.     static int sunk_with_stdio;     // make sure sync_with done only once
  156. };
  157.  
  158. inline ios& dec(ios& _strm) { _strm.setf(ios::dec,ios::basefield); return _strm; }
  159. inline ios& hex(ios& _strm) { _strm.setf(ios::hex,ios::basefield); return _strm; }
  160. inline ios& oct(ios& _strm) { _strm.setf(ios::oct,ios::basefield); return _strm; }
  161.  
  162. inline long ios::flags() const { return x_flags; }
  163. inline long ios::flags(long _l){ long _lO; _lO = x_flags; x_flags = _l; return _lO; }
  164.  
  165. inline long ios::setf(long _l,long _m){ long _lO; _lO = x_flags; x_flags = (_l&_m) | (x_flags&(~_m)); return _lO; }
  166. inline long ios::setf(long _l){ long _lO; _lO = x_flags; x_flags |= _l; return _lO; }
  167. inline long ios::unsetf(long _l){ long _lO; _lO = x_flags; x_flags &= (~_l); return _lO; }
  168.  
  169. inline int ios::width() const { return x_width; }
  170. inline int ios::width(int _i){ int _iO; _iO = (int)x_width; x_width = _i; return _iO; }
  171.  
  172. inline ostream* ios::tie(ostream* _os){ ostream* _osO; _osO = x_tie; x_tie = _os; return _osO; }
  173. inline ostream* ios::tie() const { return x_tie; }
  174. inline char ios::fill() const { return x_fill; }
  175. inline char ios::fill(char _c){ char _cO; _cO = x_fill; x_fill = _c; return _cO; }
  176. inline int ios::precision(int _i){ int _iO; _iO = (int)x_precision; x_precision = _i; return _iO; }
  177. inline int ios::precision() const { return x_precision; }
  178.  
  179. inline int ios::rdstate() const { return state; }
  180.  
  181. // inline ios::operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  182. inline int ios::operator!() const { return state&(badbit|failbit); }
  183.  
  184. inline int  ios::bad() const { return state & badbit; }
  185. inline void ios::clear(int _i){ state = _i; }
  186. inline int  ios::eof() const { return state & eofbit; }
  187. inline int  ios::fail() const { return state & (badbit | failbit); }
  188. inline int  ios::good() const { return state == 0; }
  189.  
  190. inline streambuf* ios::rdbuf() const { return bp; }
  191.  
  192. inline long _HFAR_ & ios::iword(int _i) const { return x_statebuf[_i] ; }
  193. inline void _HFAR_ * _HFAR_ & ios::pword(int _i) const { return (void _HFAR_ * _HFAR_ &)x_statebuf[_i]; }
  194.  
  195. // Restore default packing
  196. #pragma pack()
  197.  
  198. #endif 
  199.